//
// Created by wenbo on 24-9-7.
//

#ifndef DRV_MRC_HE_H
#define DRV_MRC_HE_H

#include "drv_mrc.h"
#include "filter.h"
#include "drv_key.h"
#include "drv_led.h"

#pragma pack(1)
typedef struct {
    float raw_data;
    float filtered_data;
    movingAverage_t filter;
}ADC_Sensor;
#pragma pack(0)

#pragma pack(1)
typedef struct {
    char * dev_name;      // device name

    MRC_device MRC;     // MRC device

    ADC_Sensor upper_sensor;  // upper sensor voltage
    ADC_Sensor bottom_sensor; // bottom sensor voltage
    ADC_Sensor mrc_sensor; // bottom sensor voltage

    void (* MRC_Init)(uint8_t const *dev_name, MRC_device *MRC, TIM_HandleTypeDef *htim,
            GPIO_TypeDef * INA,  uint16_t INA_PIN,
            GPIO_TypeDef * INB,  uint16_t INB_PIN,
            uint32_t PWM);
    void (* VNH7070_Multisense_ADC_process)(MRC_device *MRC1, MRC_device *MRC2);
    void (* MRC_lock)(MRC_device *MRC);
    void (* MRC_unlock)(MRC_device *MRC);
    void (* MRC_switch)(MRC_device *MRC, TIM_HandleTypeDef *htim);

    void (* MRC_set_voltage)(float voltage, MRC_device *MRC);
    uint8_t ADC_Update_Flag;

    device_key_t key0;
    device_key_t key1;

    device_led_t led0;
    device_led_t led1;

}HE_device;
#pragma pack(0)

extern HE_device MRC_HE_device;
extern uint16_t ADC_BUFFER[3];

void HE_adc_cal_filter(HE_device *device);
void drv_mrc_HE_init(char const *dev_name, HE_device *device);


#endif //DRV_MRC_HE_H
